﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HAVNet.Intros.AST
{
    public class ASTMemberDeclIndexer : ASTMemberDeclStruct
    {
        ASTFormalParamList          _formalParamList     = null;
        ASTAccessorNormals          _accessorDeclarations= null; 

        public bool                 isPartial           { get; set; }
        public ASTType              type                { get; set; }
        public ASTMemberName        name                { get; set; }
        public ASTFormalParamList   formalParamList     { get { if (null == _formalParamList) _formalParamList = new ASTFormalParamList(); return _formalParamList; } }
        public ASTAccessorNormals   accesorDeclarations { get { if (null == _accessorDeclarations) _accessorDeclarations = new ASTAccessorNormals(); return _accessorDeclarations; } }
        
        public override string ToString ()
        {
            string sAttrs = ((null == _attrGroups) ? "" : _attrGroups.ToString() + Environment.NewLine);

            //  indexersMod     =
            //      newMod      |
            //      publicMod   |
            //      protectedMod|
            //      internalMod |
            //      privateMod  |
            //      unsafeMod   |
            //      virtualMod  |
            //      sealedMod   |
            //      overrideMod |
            //      abstractMod |
            //      externMod   ,

            string mods = "";

            if (Mods.has(modifiers, Mods.newMod         )) mods += "new ";
            if (Mods.has(modifiers, Mods.publicMod      )) mods += "public ";
            if (Mods.has(modifiers, Mods.protectedMod   )) mods += "protected ";
            if (Mods.has(modifiers, Mods.internalMod    )) mods += "internal ";
            if (Mods.has(modifiers, Mods.privateMod     )) mods += "private ";
            if (Mods.has(modifiers, Mods.unsafeMod      )) mods += "unsafe ";
            if (Mods.has(modifiers, Mods.virtualMod     )) mods += "virtual ";
            if (Mods.has(modifiers, Mods.sealedMod      )) mods += "sealed ";
            if (Mods.has(modifiers, Mods.overrideMod    )) mods += "override ";
            if (Mods.has(modifiers, Mods.abstractMod    )) mods += "abstract ";
            if (Mods.has(modifiers, Mods.externMod      )) mods += "extern ";

            string sPartial = (isPartial ? "partial " : "");
            
            string sName = ( name == null ?
                ""                      /* Ejemplo 1 */
                :
                name.ToString() + "."   /* Ejemplo 2 */
            );

            return 
                sAttrs          +
                mods            +
                sPartial        +
                type.ToString() + " " +
                sName           + 
                "this [" + formalParamList.ToString() + "]" + Environment.NewLine +
                "{" + Environment.NewLine + accesorDeclarations.ToString() + Environment.NewLine + "}";
        }
    }

    //  Ejemplo 1
    //
    //  public U this [int index]
    //  {
    //      get { Statements* }
    //      set { Statements* }
    //  }

    //  Ejemplo 2
    //
    //  int IColeccionPedorra<int>.this[int i]
    //  {
    //      get { return 666; }
    //      set { arr[i] = value; }
    //  }
}

